package com.hy.erp.inventory.service;

import java.util.Collection ;
import java.util.List ;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

/*import javax.ejb.Stateless ;

import org.jboss.seam.ScopeType ;
import org.jboss.seam.annotations.Name ;
import org.jboss.seam.annotations.Scope ;
*/
import com.hy.enterprise.architecture.foundation.ArchitectureFoundationException;
import com.hy.enterprise.framework.service.business.AbstractBusinessService;
import com.hy.erp.inventory.dao.BillTypeDao;
import com.hy.erp.inventory.dao.PositionDao;
import com.hy.erp.inventory.dao.interfaces.IBillTypeDao;
import com.hy.erp.inventory.pojo.BillType;
import com.hy.erp.inventory.pojo.interfaces.IBillType;
import com.hy.erp.inventory.service.interfaces.IBillTypeService;
/**
 * 
 * <ul>
 * <li>开发作者：李冰</li>
 * <li>设计日期：2010-10-13；时间：上午09:16:58</li>
 * <li>类型名称：BillTypeService</li>
 * <li>设计目的：</li>
 * </ul>
 * <ul>
 * <b>修订编号：</b>
 * <li>修订日期：</li>
 * <li>修订作者：</li>
 * <li>修订原因：</li>
 * <li>修订内容：</li>
 * </ul>
 */
/*@ Name ( "billTypeService" )
@ Scope ( ScopeType.STATELESS )
@ Stateless*/
@Component("billTypeService")
public class BillTypeService extends AbstractBusinessService < BillTypeDao > implements IBillTypeService
{

	/**
	 * <ul>
	 * <li>开发作者：李冰</li>
	 * <li>设计日期：2010-10-11；时间：上午10:55:36</li>
	 * <li>字段类型：long；字段名称：serialVersionUID</li>
	 * <li>设计目的：</li>
	 * </ul>
	 * <ul>
	 * <b>修订编号：</b>
	 * <li>修订日期：</li>
	 * <li>修订作者：</li>
	 * <li>修订原因：</li>
	 * <li>修订内容：</li>
	 * </ul>
	 */
	private static final long	serialVersionUID	=
														- 1244584085814807337L ;

	private IBillTypeDao billTypeDao=null;
	
	

	@Resource(name="billTypeDao")
	public void setPositionTypeDao(BillTypeDao billTypeDao) {
		this.billTypeDao = billTypeDao;
	}

	@Override
	public boolean addBillType(BillType billType) {
		if (null == billType) {
			return true;
		}

		else {
			/*System.out
					.println("ssssssssssssssssssssssffffffffffffffffhghhhhhhhhhhhhhhhhhhhhhh");

			IBillTypeDao billTypeDao = (IBillTypeDao) this
					.getDao(IBillType.class);

			IBillType ibillType = billType;
			System.out.println(billType.getName() + "HHHHHHHHHHHHHH"
					+ ibillType);*/
			return billTypeDao.persist(billType);
		}
	}

	@Override
	public boolean modifyBillType(BillType billType) {

		if ((null == billType) || (null == billType.getIdentifier())
				|| (billType.getIdentifier().trim().length() == 0)) {
			return true;
		} else {

			/*//IBillTypeDao billTypeDao = (IBillTypeDao) this
				//	.getDao(IBillType.class);
			String id = billType.getIdentifier();

			BillType billType2 = (BillType) billTypeDao.findByIdentifier(id);

			Collection<String> mapKeys = billType.getPropertyNames();
			for (String mapKey : mapKeys) {
				billType.get(mapKey);
				billType2.set(mapKey, billType.get(mapKey));
			}

			IBillType billtypeEntity = billType2;

			if (null == billtypeEntity) {
				throw new ArchitectureFoundationException(
						"修改实体数据时发生错误，所需要修改的实体在数据库中并不存在");
			}*/

			return (billTypeDao.merge(billType) != null);

			// IBillTypeDao billTypeDao =
			// ( IBillTypeDao ) this
			// .getDao ( IBillType.class ) ;
			// IBillType billtypeEntity =billType;
			//
			// if ( null == billtypeEntity )
			// {
			// throw new ArchitectureFoundationException (
			// "修改实体数据时发生错误，所需要修改的实体在数据库中并不存在" ) ;
			// }
			//
			//
			// return ( billTypeDao
			// .merge ( billtypeEntity ) != null ) ;
		}

	}

	@Override
	public Integer removeBillType(String[] billTypeIds) {
		if ((null == billTypeIds) || (billTypeIds.length == 0)) {
			return new Integer(0);
		} else {
			//System.out.println(billTypeIds.length + "HHHHHHHHHHHHHH");

			//IBillTypeDao billTypeDao = (IBillTypeDao) this
				//	.getDao(IBillType.class);
			return billTypeDao.remove(billTypeIds);
		}
	}

	@Override
	public String[] addBillType(Object[] billType) {
		if (null == billType) {
			return null;
		}

		else {

			//IBillTypeDao billTypeDao = (IBillTypeDao) this
				//	.getDao(IBillType.class);

			BillType[] billTypes = new BillType[billType.length];
			for (int i = 0; i < billType.length; i++) {
				BillType billType2 = (BillType) billType[i];
				billTypes[i] = billType2;
			}

			return billTypeDao.persist(billTypes);
		}

	}

	@Override
	public List<BillType> getAllBillType() {

		//IBillTypeDao billTypeDao = (IBillTypeDao) this.getDao(IBillType.class);
		return billTypeDao.find();
	}

	@Override
	public String[] modifyBillType(Object[] billType) {

		if (null == billType) {
			return null;
		}

		else {

			//IBillTypeDao billTypeDao = (IBillTypeDao) this
				//	.getDao(IBillType.class);

			BillType[] billTypes = new BillType[billType.length];
			for (int i = 0; i < billType.length; i++) {
				BillType billType2 = (BillType) billType[i];
				String id = billType2.getIdentifier();

				BillType billType3 = (BillType) billTypeDao
						.findByIdentifier(id);

				Collection<String> mapKeys = billType2.getPropertyNames();
				for (String mapKey : mapKeys) {
					billType2.get(mapKey);
					billType3.set(mapKey, billType2.get(mapKey));
				}

				billTypes[i] = billType3;
			}

			return billTypeDao.merge(billTypes);
		}

	}


}
